<style scoped>

</style>
<template>
    <div class="tax-code-tax-rate-page">
        <el-form :inline="true" :model="formInline" class="demo-form-inline" style="border-bottom:1px solid #ccc;">
            <!--法人名称-->
            <el-form-item :label="nowLangue.legalName" class="selectMB10">
                <el-select size="mini" v-if="legalPersonLists.length> 1" clearable v-model="formInline.legalPersonName"   :placeholder="nowLangue.pleaseSelect">
                    <el-option v-for="(legalPerson,index) in legalPersonLists" :key="index" :label="legalPerson.legalPersonName" :value="legalPerson.legalPersonName">
                    </el-option>
                </el-select>
                <el-input size="mini" disabled v-else v-model="formInline.legalPersonName" ></el-input>
            </el-form-item>
            <!--产品线名称-->
            <el-form-item :label="nowLangue.productLine+nowLangue.name" class="selectMB10">
                <el-input size="mini" v-model="formInline.lineName" :placeholder="nowLangue.pleaseImport+nowLangue.productLine+nowLangue.name"></el-input>
            </el-form-item>
            <!--产品线编码-->
            <el-form-item :label="nowLangue.productLine+nowLangue.code" class="selectMB10">
                <el-input size="mini" v-model="formInline.lineCode" :placeholder="nowLangue.pleaseImport+nowLangue.productLine+nowLangue.code"></el-input>
            </el-form-item>
            <!--责任人账号-->
            <el-form-item :label="nowLangue.responsiblePAccountNo" class="selectMB10">
                <el-input size="mini"  :placeholder="nowLangue.pleaseImport+nowLangue.responsiblePAccountNo"></el-input>
            </el-form-item>
            <!--责任人姓名-->
            <el-form-item :label="nowLangue.responsiblePAccountName" class="selectMB10">
                <el-input size="mini"  :placeholder="nowLangue.pleaseImport+nowLangue.responsiblePAccountName"></el-input>
            </el-form-item>
            <!--当前状态-->
            <el-form-item :label="nowLangue.currStatus" class="selectMB10">
                <el-select size="mini" clearable v-model="formInline.status" :placeholder="nowLangue.pleaseSelect" style="width:90px;" >
                    <el-option v-for="(status,index) in statusLists" :key="index" :label="status.label" :value="status.value"></el-option>
                </el-select>
            </el-form-item>
            <!--创建时间-->
            <el-form-item :label="nowLangue.creationTime" class="purchase_label selectMB10" >
                <el-date-picker type="date" size="mini" :editable="false" v-model="formInline.startTime" :placeholder="nowLangue.pleaseSelect+nowLangue.startDate" ></el-date-picker>
                &nbsp;{{nowLangue.to}}&nbsp;
                <el-date-picker type="date" size="mini" :editable="false" v-model="formInline.endTime" :placeholder="nowLangue.pleaseSelect+nowLangue.endDate" ></el-date-picker>
            </el-form-item>
            <!--创建人-->
            <el-form-item :label="nowLangue.founder" class="selectMB10">
                <el-input size="mini" v-model="formInline.createStaff" :placeholder="nowLangue.pleaseImport+nowLangue.founder"></el-input>
            </el-form-item>
            <el-form-item class="selectMB10">
                <!--查询-->
                <el-button class="bolder outsideBtnBS selectAll" :disabled="selectDisabled" size="mini" type="danger" @click="queryLine()" v-text="nowLangue.query"></el-button>
            </el-form-item>
        </el-form>
        <!--表格-->
        <!--产品线列表：-->
        <label class="default-label" v-text="nowLangue.productLineList"></label>
        <!--新增按钮-->
        <!--新增-->
        <el-button class="bolder outsideBtnBS" size="mini" type="danger" @click="createNew()" v-text="nowLangue.create"></el-button>
        <el-table :data="productData" border style="width: 100%;" v-loading.body="loading" element-loading-text="拼命加载中">
            <!--序-->
            <el-table-column type="index" header-align="center" align="center" :label="nowLangue.sequence"  width="40"></el-table-column>
            <!--操作-->
            <el-table-column  :label="nowLangue.operate" header-align="center" align="center" width="80">
                <template scope="scope">
                    <!--禁用-->
                    <div class="operationItem bolder" v-if="scope.row.status" @click="handleStatus(scope.$index,scope.row)" v-text="nowLangue.forbidden"></div>
                    <!--启用-->
                    <div class="operationItem bolder" v-else @click="handleStatus(scope.$index,scope.row)" v-text="nowLangue.enable"></div>
                    <!--修改-->
                    <div class="operationItem disabled bolder" v-if="scope.row.status" v-text="nowLangue.update"></div>
                    <!--修改-->
                    <div class="operationItem bolder" v-else @click="updateCorFact(scope.$index,scope.row)" v-text="nowLangue.update"></div>
                </template>
            </el-table-column>
            <!--产品线编码-->
            <el-table-column prop="lineCode" :label="nowLangue.productLine+nowLangue.code" header-align="center" show-overflow-tooltip></el-table-column>
            <!--产品线名称-->
            <el-table-column prop="lineName" :label="nowLangue.productLine+nowLangue.name" header-align="center" show-overflow-tooltip></el-table-column>
            <!--所属法人-->
            <el-table-column prop="legalPersonName" :label="nowLangue.LegalUnderItsJurisdiction" header-align="center" width="150" show-overflow-tooltip></el-table-column>
            <!--责任人账号-->
            <el-table-column prop="" :label="nowLangue.responsiblePAccountNo" header-align="center"  show-overflow-tooltip></el-table-column>
            <!--责任人姓名-->
            <el-table-column prop="" :label="nowLangue.responsiblePAccountName" header-align="center"  show-overflow-tooltip></el-table-column>
            <!--当前状态-->
            <el-table-column prop="statusName" :label="nowLangue.currStatus" header-align="center" align="center" width="80" ali show-overflow-tooltip></el-table-column>
            <!--时间-->
            <el-table-column prop="time" label="nowLangue.time" header-align="center"  show-overflow-tooltip width="180"></el-table-column>
            <!--创建人-->
            <el-table-column prop="createStaff" :label="nowLangue.founder" header-align="center" width="80" show-overflow-tooltip></el-table-column>
        </el-table>
        <!--新建弹窗-->
        <!--新增产品线责任人信息-->
        <el-dialog :title="nowLangue.create+nowLangue.personResponsibleForProductLine" :visible.sync="dialogForm1Visible" size="tiny" :lock-scroll="false">
            <el-form :inline="true" :model="addLineForm" class="demo-form-inline label-minW95" style="border-bottom:1px solid #ccc;" ref="addLineForm"> 
                <!--法人名称-->
                <el-form-item :label="nowLangue.legalName" prop="taxCode"  :rules="[{ required: true, message: nowLangue.required}]" >
                    <el-select size="mini" v-if="legalPersonLists.length> 1" clearable v-model="addLineForm.legalPersonName"   :placeholder="nowLangue.pleaseSelect">
                        <el-option v-for="(legalPerson,index) in legalPersonLists" :key="index" :label="legalPerson.legalPersonName" :value="legalPerson.legalPersonName">
                        </el-option>
                    </el-select>
                    <el-input size="mini" disabled v-else v-model="addLineForm.legalPersonName" placeholder=""></el-input>
                </el-form-item>
                <!--产品线名称-->
                <el-form-item :label="nowLangue.productLine+nowLangue.name" prop="lineCode"  :rules="[{ required: true, message: nowLangue.required}]">
                    <el-select size="mini" clearable v-model="addLineForm.lineName"   :placeholder="nowLangue.pleaseSelect">
                        <el-option label="数码选件" value="数码选件"></el-option>
                    </el-select>
                </el-form-item>
                <!--产品线编码-->
                <el-form-item :label="nowLangue.productLine+nowLangue.code" prop="lineName"  :rules="[{ required: true, message: nowLangue.required}]">
                    <el-input size="mini"  v-model="addLineForm.lineCode"  disabled ></el-input>
                </el-form-item>
                <!--责任人姓名-->
                <el-form-item :label="nowLangue.responsiblePAccountName" prop="staffName"  :rules="[{ required: true, message: nowLangue.required}]">
                    <el-select size="mini" clearable v-model="addLineForm.staffName"   :placeholder="nowLangue.pleaseSelect">
                        <el-option label="小王" value="小王"></el-option>
                        <el-option label="小李" value="小李"></el-option>
                    </el-select>
                </el-form-item>
                <!--责任人账号-->
                <el-form-item :label="nowLangue.responsiblePAccountNo" prop="lineName"  :rules="[{ required: true, message: nowLangue.required}]">
                    <el-input size="mini" v-model="addLineForm.staffCode" disabled ></el-input>
                </el-form-item>
                <!--状态-->
                <el-form-item :label="nowLangue.status" >
                    <el-radio-group v-model="addLineForm.status">
                        <!-- 启用 -->
                        <el-radio :label="true" v-cloak>{{nowLangue.enable}}</el-radio>
                        <!-- 禁用 -->
                        <el-radio :label="false" v-cloak>{{nowLangue.forbidden}}</el-radio>
                    </el-radio-group>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <!--保存-->
                <el-button class="bolder outsideBtnBS" size="mini" type="danger" @click="saveProductLineStaffing" v-text="nowLangue.save" :disabled="savePLSDisabled"></el-button>
                <!--取消-->
                <el-button class="bolder outsideBtnBS" size="mini" type="danger" @click="cancleCorFact" v-text="nowLangue.cancel"></el-button>
            </div>
        </el-dialog>
        <!--修改弹窗-->
        <!--修改产品线责任人信息-->
        <el-dialog :title="nowLangue.update+nowLangue.personResponsibleForProductLine" :visible.sync="dialogForm2Visible" size="tiny" :lock-scroll="false">
            <el-form :inline="true" :model="updateLineForm" class="demo-form-inline label-minW95" style="border-bottom:1px solid #ccc;" ref="updateLineForm">
                <!--法人名称-->
                <el-form-item :label="nowLangue.legalName" class="selectMB10" prop="legalPersonName" :rules="[{ required: true, message: nowLangue.required}]">
                    <el-input size="mini" disabled  v-model="updateLineForm.legalPersonName" placeholder=""></el-input>
                </el-form-item>
                <!--产品线名称-->
                <el-form-item :label="nowLangue.productLine+nowLangue.name" prop="lineName" class="selectMB10" :rules="[{ required: true, message: nowLangue.required}]">
                    <el-input  v-model="updateLineForm.lineName" disabled :placeholder="nowLangue.pleaseImport+nowLangue.productLine+nowLangue.name"></el-input>
                </el-form-item>
                <!--产品线编码-->
                <el-form-item :label="nowLangue.productLine+nowLangue.code"  prop="lineCode" class="selectMB10" :rules="[{ required: true, message: nowLangue.required}]">
                    <el-input  v-model="updateLineForm.lineCode" disabled></el-input>
                </el-form-item>
                <!--责任人姓名-->
                <el-form-item :label="nowLangue.responsiblePAccountName" prop="staffName"  :rules="[{ required: true, message: nowLangue.required}]">
                    <el-select size="mini" clearable v-model="updateLineForm.staffName"   :placeholder="nowLangue.pleaseSelect">
                        <el-option label="小王" value="小王"></el-option>
                        <el-option label="小李" value="小李"></el-option>
                    </el-select>
                </el-form-item>
                <!--责任人账号-->
                <el-form-item :label="nowLangue.responsiblePAccountNo" prop="lineName"  :rules="[{ required: true, message: nowLangue.required}]">
                    <el-input size="mini" v-model="addLineForm.staffCode" disabled ></el-input>
                </el-form-item>
                <!--状态-->
                <el-form-item :label="nowLangue.status" class="selectMB10">
                    <el-radio-group v-model="updateLineForm.status">
                        <!-- 启用 -->
                        <el-radio :label="true" v-cloak>{{nowLangue.enable}}</el-radio>
                        <!-- 禁用 -->
                        <el-radio :label="false" v-cloak>{{nowLangue.forbidden}}</el-radio>
                    </el-radio-group>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <!--保存-->
                <el-button class="bolder outsideBtnBS" size="mini" type="danger" @click="saveUpdateProductLineStaffing" v-text="nowLangue.save" :disabled="saveUPLSDisabled"></el-button>
                <!--取消-->
                <el-button class="bolder outsideBtnBS" size="mini" type="danger" @click="cancleUpdateCorFact" v-text="nowLangue.cancel"></el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
    export default {
        data() {
            return {
                nowLangue:{},
                // 查询表单
                formInline:{
                    legalPersonId:'',
                    legalPersonName:'',
                    lineName:'',
                    lineCode:'',
                    status:'',
                    startTime:'',
                    endTime:'',
                    createStaff:'',
                },
                statusLists:[],   //当前状态下拉列表
                legalPersonLists:[],//法人名称列表
                labelWidth:"80px",
                addLineForm:{
                    legalPersonId:'',
                    legalPersonName:'',
                    lineName:'',
                    lineCode:'',
                    staffName:'',
                    staffCode:'',
                    status:true
                },
                updateLineForm:{
                    legalPersonId:'',
                    legalPersonName:'',
                    lineName:'数码选件',
                    lineCode:'M',
                    staffName:'',
                    staffCode:'',
                    status:true
                },
                legalPersonDropDown:[], //法人名称
                productData:[
                    {
                        legalPersonName:"联想服务海外限公司",
                        lineName:'产品线名称',
                        lineCode:'产品线编码',
                        time:'2017-08-23 00:00:00',
                        createStaff:'小李',
                        status:true,
                        statusName:"启用"
                    },
                    {
                        legalPersonName:"联想服务海外限公司",
                        lineName:'产品线名称',
                        lineCode:'产品线编码',
                        time:'2017-08-23 00:00:00',
                        createStaff:'小王',
                        status:false,
                        statusName:"禁用"
                    }
                ],
                loading:false,
                disabled:false,
                //弹窗
                dialogForm1Visible:false,
                dialogForm2Visible:false,
                // 分页
                //查询禁用
                selectDisabled:false,
                savePLSDisabled:false,   // 新增弹窗中保存操作按钮禁用
                saveUPLSDisabled:false    // 修改弹窗中保存操作按钮禁用
            };
        },
        created:function(){
            var _this=this;
            _this.languageType=="zh"?_this.nowLangue=_this.language.zh:_this.nowLangue=_this.language.en;
        },
        computed:{
            // powerData(){
            //     return this.$store.state.powerData;
            // },
            languageType(){
                return this.$store.state.languageType;
            }
        },
        watch:{
            languageType(){
                var _this=this;
                _this.languageType=="zh"?_this.nowLangue=_this.language.zh:_this.nowLangue=_this.language.en;
            }
        },
        //进入页面立即运行此方法
        mounted: function () {
            var _this = this;
            _this.$store.commit('currentActive', 'ProductLineStaffing');
            // //ajax前后查询按钮禁用
            // $(".selectAll").ajaxStart(function(){
            //     _this.selectDisabled=true;
            // });
            // $(".selectAll").ajaxStop(function(){
            //     _this.selectDisabled=false;
            // });
            _this.legalPersonDropDownValue();
        },
        methods:{
            // 查询法人名称
            legalPersonDropDownValue(){  //法人名称下拉列表值
                var _this = this;
                $.ajax({
                    type:'GET',
                    url:_this.procurement_service+"legalPerson/ofCurrentUser",
                    cache:false,
                    success:function(data){
                        if(data.success){
                            _this.legalPersonLists = data.data;
                            if(_this.legalPersonLists.length == 1){
                                _this.formInline.legalPersonId =_this.legalPersonLists[0].id;
                                _this.formInline.legalPersonName =_this.legalPersonLists[0].legalPersonName;
                                _this.updateLineForm.legalPersonId =_this.legalPersonLists[0].id;
                                _this.updateLineForm.legalPersonName =_this.legalPersonLists[0].legalPersonName;
                                _this.addLineForm.legalPersonId =_this.legalPersonLists[0].id;
                                _this.addLineForm.legalPersonName =_this.legalPersonLists[0].legalPersonName;

                            }
                        }else{
                            _this.common.errorTip(data.errorMessage);
                        }
                    }
                })
            },
            //查询税码税率列表
            queryLine(){
                /*var _this=this;
                 _this.loading=true;
                 var tmp={
                 taxCode:_this.formInline.taxCode,
                 taxDec:_this.formInline.taxDec,
                 tax:_this.formInline.tax,
                 status:_this.formInline.status,
                 pageIndex:_this.pageIndex,
                 pageSize:_this.pageSize
                 };
                 _this.selectDisabled=true;
                 $.ajax({
                 type: 'POST',
                 url: _this.metadata_service+"tax/queryPage",
                 cache: false,
                 data:JSON.stringify(tmp),
                 dataType:'JSON',
                 contentType: "application/json;charset=utf-8",
                 success: function (data) {
                 if (data.success) {
                 _this.loading=false;
                 _this.isPaging=true;
                 _this.totalPage=data.data.totalPage;
                 _this.totalNumber=data.data.totalNumber;
                 _this.corFactoryData=data.data.dataList;
                 }else{
                 _this.common.errorTip(data.errorMessage)
                 }
                 _this.selectDisabled=false;
                 }
                 });*/
            },
            //新增税码税率信息
            createNew(){
                this.dialogForm1Visible=true;
            },
            //新建保存
            saveProductLineStaffing(){
                /*var _this=this;
                 _this.$refs["addLineForm"].validate((valid) => {
                 if (valid) {
                 if(_this.taxIsNumber){
                 var tmp={
                 taxCode:_this.addLineForm.taxCode,   //去除税码两边的空格
                 taxDec:_this.addLineForm.taxDec,
                 tax:_this.addLineForm.tax,
                 status:_this.addLineForm.status,
                 };
                 _this.savePLSDisabled=true;
                 $.ajax({
                 type: 'POST',
                 url: _this.metadata_service+"tax/save",
                 cache: false,
                 data:JSON.stringify(tmp),
                 dataType:'JSON',
                 contentType: "application/json;charset=utf-8",
                 success: function (data) {
                 if (data.success) {
                var success=_this.languageType=="zh"?'保存成功':'Save Success';
                _this.common.successTip(success);
                 _this.dialogForm1Visible=false;
                 _this.queryTaxSheet();
                 }else{
                 _this.common.errorTip(data.errorMessage);
                 }
                 _this.savePLSDisabled=false;
                 }
                 });
                 }else{
                 _this.common.errorTip("税率必须为数字！");
                 }
                 } else {
                var  err=_this.common.formErrorInfo();
                _this.common.errorTip(err);
                 return false;
                 }
                 });*/
            },
            //新建取消
            cancleCorFact(){
                var _this=this;
                _this.dialogForm1Visible=false;

                this.$refs['addLineForm'].resetFields();
                /*if(this.$refs['addLineForm']) {
                 this.$refs['addLineForm'].resetFields();
                 }
                 _this.addLineForm.taxCode="";
                 _this.addLineForm.taxDec="";
                 _this.addLineForm.tax="";
                 _this.addLineForm.status=false;*/
            },
            // 操作启用禁用
            handleStatus(index, row){
                /*var _this=this;
                 if(row.status){
                 row.status = false;
                 }else{
                 row.status = true;
                 }
                 var tmp={id: row.id,status: row.status};
                 $.ajax({
                 type: 'POST',
                 url: _this.metadata_service+"tax/updateStatus",
                 cache: false,
                 data:JSON.stringify(tmp),
                 dataType:'JSON',
                 contentType: "application/json;charset=utf-8",
                 success: function (data) {
                 if (data.success) {
                 // 当前状态的显示
                 if(row.status){
                 row.statusName = "启用";
                var success=_this.languageType=="zh"?'启用成功！':'Enable success';
                _this.common.successTip(success);
                 }else{
                 row.statusName = "禁用";
                var success=_this.languageType=="zh"?'禁用成功！':'Disable success';
                _this.common.successTip(success);
                 }
                 }else
                 _this.common.errorTip(data.errorMessage);
                 }
                 });*/
            },
            //点击修改
            updateCorFact(index,row){
                var _this=this;
                _this.dialogForm2Visible=true;
                /*if(this.$refs['updateLineForm']) {
                 this.$refs['updateLineForm'].resetFields();
                 }
                 _this.updateLineForm.id = row.id;
                 _this.updateLineForm.taxCode = row.taxCode;
                 _this.updateLineForm.taxDec = row.taxDec;
                 _this.updateLineForm.tax = row.tax;
                 _this.updateLineForm.status = row.status;*/
            },
            //修改保存
            saveUpdateProductLineStaffing(){
                var _this=this;
                // console.log(_this.updateLineForm.tax);
                // _this.$refs["updateLineForm"].validate((valid) => {
                //     if (valid) {
                //         if(_this.taxIsNumber){
                //             var tmp={
                //                 id:_this.updateLineForm.id,
                //                 taxCode:_this.updateLineForm.taxCode,
                //                 taxDec:_this.updateLineForm.taxDec,
                //                 tax:_this.updateLineForm.tax,
                //                 status: _this.updateLineForm.status
                //             };
                // _this.saveUPLSDisabled=true;
                //             $.ajax({
                //                 type: 'POST',
                //                 url: _this.metadata_service+"tax/update",
                //                 cache: false,
                //                 data:JSON.stringify(tmp),
                //                 dataType:'JSON',
                //                 contentType: "application/json;charset=utf-8",
                //                 success: function (data) {
                //                     if (data.success) {
                //                         var success=_this.languageType=="zh"?'修改成功！':'Modify successfully';
                //                         _this.common.successTip(success);
                //                         _this.dialogForm2Visible=false;
                //                         _this.queryTaxSheet();
                //                     }else{
                                            // _this.common.errorTip(data.errorMessage);
                //                     }
                //                     _this.saveUPLSDisabled=false;    
                //                 }
                //             });
                //         }else{
                //             _this.common.errorTip("税率必须为数字！");
                //         }
                //     } else {
                //         var  err=_this.common.formErrorInfo();
                //         _this.common.errorTip(err);
                //         return false;
                //     }
                // });
            },
            //修改取消
            cancleUpdateCorFact(){
                var _this=this;
                _this.dialogForm2Visible=false;
                this.$refs['updateLineForm'].resetFields();
            },
            // // ===================================
            // successTip(p) {     //成功时的提示信息
            //     this.$notify({
            //         title: this.nowLangue.success,
            //         message: p,
            //         type: 'success'
            //     });
            // },
            // errorTip(p) {     //错误提示
            //     this.$notify.error({
            //         title: this.nowLangue.error,
            //         message: p
            //     });
            // }

        }
    }
</script>



